package com.gbx.coordinatordemo;

import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.design.widget.SwipeDismissBehavior;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class MainActivity extends AppCompatActivity implements SwipeDismissBehavior.OnDismissListener {
    private TextView text;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        text = (TextView) findViewById(R.id.mian_text);
//        CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) text.getLayoutParams();
        //behavior性能行为：侧滑隐藏
//        SwipeDismissBehavior<TextView> behavior = new SwipeDismissBehavior<>();
//        behavior.setListener(this);
//        layoutParams.setBehavior(behavior);
        List<String> list = new ArrayList<>();
        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler);
        for (int i = 0; i < 100; i++) {
            list.add(String.format(Locale.CHINA,"第%03d条数据", i + 1));
        }
        //一种设置模式：
//        recyclerView.setAdapter(new MyAdapter(this,list));
//        MyBehavior<TextView> behavior = new MyBehavior<>();
//        layoutParams.setBehavior(behavior);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    }

    @Override
    public void onDismiss(View view) {
        view.setVisibility(View.GONE);//真正被删除，不能复原
        Snackbar.make(view,"Snackbar",Snackbar.LENGTH_LONG)
                .setAction("删除了一个控件", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        text.setVisibility(View.VISIBLE);//现在可以找回
                        ViewCompat.animate(text).alpha(1).start();
                    }
                })
                .show();
    }

    @Override
    public void onDragStateChanged(int state) {

    }
}
